package com.ycsj.goldmedalnewconcept.teacher.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ycsj.goldmedalnewconcept.R;
import com.ycsj.goldmedalnewconcept.teacher.bean.RvZsdInfo;

import java.util.List;

/**
 * 按知识点搜索的列表适配器
 * Created by Administrator on 2019/2/22 0022.
 */

public class SearchPopLvAdapter extends BaseQuickAdapter<RvZsdInfo, BaseViewHolder> {

    private List<RvZsdInfo> datas;

    public SearchPopLvAdapter(int layoutResId, @Nullable List<RvZsdInfo> data) {
        super(layoutResId, data);
        this.datas = data;
    }

    @Override
    protected void convert(BaseViewHolder helper, final RvZsdInfo item) {
        int postion = helper.getLayoutPosition();
        //知识点名称
        TextView tvName = helper.getView(R.id.tv_name);
        if (0 == postion) {
            tvName.setVisibility(View.VISIBLE);
        } else {
            if (datas.get(postion).name.equals(datas.get(postion - 1).name)) {
                tvName.setVisibility(View.GONE);
            } else {
                tvName.setVisibility(View.VISIBLE);
            }
        }
        tvName.setText(item.name);

        //知识点内容
        TextView tvContent = helper.getView(R.id.tv_content);
        tvContent.setText(item.content);

        //是否选中的图标
        ImageView lv = helper.getView(R.id.lv);
        if (item.isChoosed) {
            lv.setImageResource(R.drawable.checked);
        } else {
            lv.setImageResource(R.drawable.unchecked);
        }


        //选中图标的整体布局
        RelativeLayout rl = helper.getView(R.id.rl_choose);
        rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                item.isChoosed = !item.isChoosed;
                notifyDataSetChanged();
            }
        });
    }


}
